package io.renren.modules.examination.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.examination.dao.ExaminationPaperDao;
import io.renren.modules.examination.entity.ExaminationPaperEntity;
import io.renren.modules.examination.service.ExaminationPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("examinationPaperService")
public class ExaminationPaperServiceImpl extends ServiceImpl<ExaminationPaperDao, ExaminationPaperEntity> implements ExaminationPaperService {

    @Autowired
    ExaminationPaperDao examinationPaperDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<ExaminationPaperEntity> page = this.selectPage(
                new Query<ExaminationPaperEntity>(params).getPage(),
                new EntityWrapper<ExaminationPaperEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getExaminationPaperList(Map<String, Object> params) {
        PageUtils page=new PageUtils();
        int total=examinationPaperDao.getExaminationPaperTotal(params);
        page.setPageSize(Integer.parseInt((String) params.get("limit")));
        page.setList(examinationPaperDao.getExaminationPaperList(params));
        page.setTotalCount(total);
        page.setCurrPage(Integer.parseInt((String) params.get("page")));
        page.setTotalPage(Constant.getTotalPage(page.getTotalCount(),page.getPageSize()));
        return page;
    }

    @Override
    public boolean deleteAll(List list) {
        boolean a = examinationPaperDao.deleteExaminationQuestionsByPaperId(list);
        boolean b = examinationPaperDao.deleteExaminationResultTypeByPaperId(list);
        boolean c = this.deleteBatchIds(list);
        if (a && b && c)
            return true;
        else
            return false;
    }
}
